using System;
using System.Linq;

namespace TicTacToe.Core
{
    public sealed class Turn
    {
        public Player Player { get; private set; }

        public int X1 { get; private set; }
        public int X2 { get; private set; }
        public int X3 { get; private set; }

        public DateTime Timestamp { get; private set; }

        public override string ToString()
        {
            return string.Format("({0}|{1}|{2})", X1, X2, X3);
        }

        public int[] ToArray()
        {
            return new[] {X1, X2, X3};
        }

        public Turn(Player player, params int[] xValues)
        {
            if (xValues.Length != 3)
                throw new ArgumentException("invalid number of arguments");

            if (xValues.Any(n => n < 0))
                throw new ArgumentException("xValues must be > 0");

            Player = player;
            X1 = xValues[0];
            X2 = xValues[1];
            X3 = xValues[2];

            Timestamp = DateTime.Now;
        }
    }
}